﻿using Compass.Wasm.Shared.Categories;
using Compass.Wasm.Shared.Wms;
using Zack.DomainCommons.Models;

namespace Compass.WmsService.Domain.Entities;

public record StockIn : AggregateRootEntity
{
    public Guid CargoId { get; private set; }

    public string? PoNumber { get;private set; }
    public string? VendorNumber { get;private set; }
    public double Price { get;private set; }

    public double TransitQuantity { get;private set; }
    public double Quantity { get;private set; }
    public DateTime? ExpectedTime { get;private set; }
    public DateTime? InTime { get;private set; }

    public Guid OperatorId { get;private set; }//入库人
    public string? Remarks { get ;private set ; }

    private StockIn() { }
    public StockIn(Guid id, Guid cargoId, string? poNumber,string? vendorNumber,double price,double transitQuantity,double quantity, DateTime? expectedTime, DateTime? inTime,Guid operatorId, string? remarks)
    {
        Id=id;
        CargoId=cargoId;

        PoNumber=poNumber;
        VendorNumber = vendorNumber;
        Price=price;

        TransitQuantity=transitQuantity;
        Quantity = quantity;
        ExpectedTime = expectedTime;
        InTime = inTime;
        OperatorId=operatorId;
        Remarks=remarks;
    }

    public void Update(StockInDto dto)
    {
        ChangePoNumber(dto.PoNumber)
            .ChangeVendorNumber(dto.VendorNumber)
            .ChangePrice(dto.Price)
            .ChangeTransitQuantity(dto.TransitQuantity)
            .ChangeQuantity(dto.Quantity)
            .ChangeExpectedTime(dto.ExpectedTime)
            .ChangeInTime(dto.InTime)
            .ChangeRemarks(dto.Remarks);

        NotifyModified();
    }

    public StockIn ChangePoNumber(string? poNumber)
    {
        PoNumber=poNumber;
        return this;
    }
    public StockIn ChangeVendorNumber(string? vendorNumber)
    {
        VendorNumber=vendorNumber;
        return this;
    }
    public StockIn ChangePrice(double price)
    {
        Price=price;
        return this;
    }
    public StockIn ChangeTransitQuantity(double transitQuantity)
    {
        TransitQuantity=transitQuantity;
        return this;
    }
    public StockIn ChangeQuantity(double quantity)
    {
        Quantity=quantity;
        return this;
    }
    public StockIn ChangeExpectedTime(DateTime? expectedTime)
    {
        ExpectedTime=expectedTime;
        return this;
    }
    public StockIn ChangeInTime(DateTime? inTime)
    {
        InTime=inTime;
        return this;
    }
    public StockIn ChangeRemarks(string? remarks)
    {
        Remarks=remarks;
        return this;
    }
}